package com.woniu.controller;/*
 *
 * @author   米雷
 * @Description  用户对物品相关操作
 * @Date:create in 17:35 2020-03-24
 *
 * */

import com.woniu.dto.GoodCollect;
import com.woniu.dto.OrderAndDetail;
import com.woniu.service.GoodsService;
import com.woniu.service.OrderService;
import com.woniu.userLog.LogPoint;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@Api(tags = "商品相关")
@CrossOrigin(allowCredentials = "true", maxAge = 3600)
@Controller
@RequestMapping("/goods")
public class GoodsController {

    @Autowired
    GoodsService goodsService;

    @Autowired
    OrderService orderService;
    /*
     *  @auth:米雷
     *  查看收藏的商品
     *
     *
     **/
    @ApiOperation(value = "收藏的商品")
    @GetMapping("/getcollect")
    @ResponseBody
    @LogPoint("用户查看收藏的商品")
    public GoodCollect getCollect(Long id)
    {
        GoodCollect goodCollect = goodsService.getCollect(id);
        System.out.println(goodCollect);
        return goodCollect;
    }

    /*
     *  @auth:米雷
     *  删除收藏的商品
     *
     **/
    @ApiOperation(value = "删除收藏的商品")
    @DeleteMapping("/deleteCollect")
    @ResponseBody
    @LogPoint("用户删除收藏的商品")
    public String deleteCollect(Long id)
    {
        String res = goodsService.deleteCollect(id);
        return res;
    }


    /*
     *  @auth:米雷
     *  查看用户的订单(订单表，订单详情表，商品表）
     *
     **/
    @ApiOperation(value = "查看商品订单")
    @GetMapping("/getOrder")
    @ResponseBody
    @LogPoint("用户查看商品订单")
    public OrderAndDetail getUserOrder(Long id)
    {
        OrderAndDetail order = orderService.getUserOrder(id);
        return order;
    }
    /*
     *  @auth:米雷
     *  取消订单(订单表，订单详情表），将订单状态变为7
     *
     **/
    @ApiOperation(value = "取消商品订单")
    @GetMapping("/deleteOrder")
    @ResponseBody
    @LogPoint("用户取消商品订单")
    public String deleteOrder(Long id)
    {
       String res = orderService.deleteOrder(id);
        return res;
    }
}
